from logging import exception
from time import sleep, strftime,localtime,time
from selenium.webdriver.common.by import By
from common.Utils import ForumDriver
from selenium.common.exceptions import NoSuchFrameException
scrpath = "C:\\ForumTest\\Screenshot"
class ForumUserRegister:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = ForumDriver.driver
        url = "http://127.0.0.1:58080/sign-up.html"
        self.driver.get(url)

    def RegisterTest(self):
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > h2")

        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(2) > label")
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("test6")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(3) > label")
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").send_keys("test6")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(4) > label")
        self.driver.find_element(By.CSS_SELECTOR,"#password").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(5) > label")
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").send_keys("123")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        file_name = strftime("%Y-%m-%d %H-%M-%S", localtime(time())) + ".png"
        path = scrpath + "\\" + file_name
        self.driver.get_screenshot_as_file(path)
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()